class SDK {
  static api1(appKey, uid, username) {
    console.log("api1", appKey, uid, username);
  }

  static api2(appKey, token, uid) {
    console.log("api2", appKey, token, uid);
  }

  static api3(appKey, appId, uid) {
    console.log("api3", appKey, appId, uid);
  }
}

//---------------------------------------------------------------------------------------------------
console.log(
    "----------------------------直接调用 [第一个参数是固定的情况]----------------------------");

SDK.api1("myAppKey", "xiaoming", "小明");
SDK.api1("myAppKey", "xiaohong", "小红");
SDK.api1("myAppKey", "xiaogang", "小刚");
//----------------------------------------------------------------------------------------------------
console.log(
    "----------------------------抽离参数 [第一个参数是固定的情况]----------------------------");

let myApi1 = function (uid, nickname) {
  SDK.api1("myAppKey", uid, nickname);
}
myApi1("xiaoming", "小明");
myApi1("xiaohong", "小红");
myApi1("xiaogang", "小刚");
//----------------------------------------------------------------------------------------------------现在有了第二个接口
let myApi2 = function (token, uid) {
  SDK.api2("myAppKey", token, uid);
}
myApi2("token1", "xiaoming");
myApi2("token2", "xiaohong");
myApi2("token3", "xiaogang");
//----------------------------------------------------------------------------------------------------
console.log(
    "----------------------------抽离函数 [第一个参数是固定的情况]----------------------------");
// static api1(appKey, uid, username) {
//   console.log("api1", appKey, uid, username);
// }
let getMyApi = function (api) {
  return function (p1, p2) {
    api("myAppKey", p1, p2)
  }
}
let myApi1Wrap = getMyApi(SDK.api1)
let myApi2Wrap = getMyApi(SDK.api2)
myApi1Wrap("xiaoming", "小明");
myApi1Wrap("xiaohong", "小红");
myApi1Wrap("xiaogang", "小刚");
myApi2Wrap("token1", "xiaoming");
myApi2Wrap("token2", "xiaohong");
myApi2Wrap("token3", "xiaogang");
//---------------------------------------------------------------------------------------------------你碰到了另外一种类型的api，它也是3个参数，第1个参数是app的id，第2个参数是你的app的名字，两个参数都是固定不变的
console.log(
    "----------------------------抽离函数 [前两个参数参数是固定的情况]----------------------------");
let getMyApi2 = function (api) {
  return function (uid) {
    api("myAppKey", "myAppId", uid)
  }
}
let myApi3Wrap = getMyApi2(SDK.api3)
myApi3Wrap("xiaoming");
myApi3Wrap("xiaohong");
myApi3Wrap("xiaogang");
//---------------------------------------------------------------------------------------------------
console.log("----------------------------通用----------------------------");
// let generalGetMyApi = function (api) {
//   //把函数和需要固定住的参数都传递进来
//   let settledArgs = [].splice.call(arguments, 1);
//
//   //返回一个新的函数，这个函数包含了已经固定住部分参数，并且传入一些易变的参数
//   return function () {
//
//     //将不变的参数和易变的参数重新传进这个函数再执行
//     let mutableArguments = arguments;
//     api.call(null, [].concat.apply(settledArgs, mutableArguments));
//   }
// }
// call(1,23,4,)
// apply([23,3,23,])
let generalGetMyApi = function(fn) {
  var slice = Array.prototype.slice,
      __args = slice.call(arguments, 1);//arguments:[SDK.api1,"myAppKey"],__args:["myAppKey"]
  return function () {
    var __inargs = slice.call(arguments);//arguments:["xiaoming", "小明"]
    return fn.apply(null, __args.concat(__inargs));//__args.concat(__inargs):["myAppKey","xiaoming", "小明"]
  };
}
let generalMyApi1 = generalGetMyApi(SDK.api1,"myAppKey");
let generalMyApi2 = generalGetMyApi(SDK.api2,"myAppKey");
let generalMyApi3 = generalGetMyApi(SDK.api3,"myAppKey","myAppId");
generalMyApi1("xiaoming", "小明");
generalMyApi1("xiaohong", "小红");
generalMyApi1("xiaogang", "小刚");
generalMyApi2("token1", "xiaoming");
generalMyApi2("token2", "xiaohong");
generalMyApi2("token3", "xiaogang");
generalMyApi3("xiaogang");
generalMyApi3("xiaogang");
generalMyApi3("xiaogang");
